from fastapi import APIRouter
from service.pyttsx3_service import TTSService
from entity.schema.pyttsx3_schema import TTSRequest, TTSResponse
from utils.base_response import BaseResponse

router = APIRouter()
tts_service = TTSService()

@router.post("/tts", response_model=BaseResponse)
async def convert_text_to_speech(request: TTSRequest):
    audio_file = tts_service.generate_speech(request)
    return BaseResponse(
        code=200,
        msg="语音生成成功",
        data=TTSResponse(
            status="success",
            filename=audio_file.filename,
            url=f"/audio/{audio_file.filename}"
        )
    )